package mason.dp.observerjdk;

import java.util.Observable;
import java.util.Observer;

import mason.dp.observer.DisplayElement;

public class TomorrowConditionsDisplay implements Observer, DisplayElement {
	Observable obervable ;
	private float temperature;
	private float humidity;
	
	public TomorrowConditionsDisplay(Observable o) {
		this.obervable = o;
		o.addObserver(this);
	}
	
	@Override
	public void display() {
		System.out.println("明天的天气状况为（ 温度："+(temperature+10)+"  湿度：%"+(humidity+10)+")");//数据模拟，假设第二天的数据为当前数据+10
	}

	@Override
	public void update(Observable o, Object arg) {
		if(o instanceof WeatherData) {
			WeatherData wd = (WeatherData) o;
			this.temperature = wd.getTemperature();
			this.humidity = wd.getHumidity();
			display();
		}
	}

}
